package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Columns;

/**
 * 
 * @author 
 *
 */
@DAO
public interface ColumnsDAO{
	
	@SQL("SELECT * FROM Columns WHERE deleteFlag=1 ORDER BY orderNo ,id  ")
    List<Columns> queryAll();
	
	@SQL("SELECT group_concat(c.descs) as roleName FROM Columns a left join ColumnsRef b on a.id=b.columnsId left join RoleInfo c on b.roleId=c.id WHERE a.deleteFlag=1 AND a.type=:2 AND a.id =:1 ")
    List<Map> queryColums(int id,int type);
	
	@SQL("SELECT * FROM Columns WHERE deleteFlag=1 AND type=:t.type #if(:t.name!=''){and name like '%##(:t.name)%' } ORDER BY orderNo LIMIT :t.start,:t.length ")
    List<Columns> query(@SQLParam("t") Columns columns);
	
	@SQL("SELECT count(*) FROM Columns WHERE deleteFlag=1 AND type=:t.type #if(:t.name!=''){and name like '%##(:t.name)%' } ")
    int querySize(@SQLParam("t") Columns columns);
	
	@SQL("select a.id as id,a.type as type,a.subType as subType,a.name as name,a.descs as descs from Columns a join ColumnsRef b on a.id=b.columnsId join UserRoleRef c on b.roleId=c.roleId join UserInfo d on c.userId=d.id where a.deleteFlag=1 AND d.account = :1 group by a.id,a.type,a.name,a.descs")
    List<Columns> queryByAccountForColumns(String account);

    @SQL("select * from Columns where id=:1")
    Columns queryById(int id);
    
    @SQL("INSERT INTO Columns (type,subType,name,descs,stickAt,status,deleteFlag,createUser,createAt,updateUser,updateAt,orderNo) VALUES (:t.type,:t.subType,:t.name,:t.descs,:t.stickAt,:t.status,1,:t.createUser,now(),:t.updateUser,now(),:t.orderNo)")
    void create(@SQLParam("t") Columns columns);
	
	@SQL("UPDATE Columns SET type=:t.type,subType=:t.subType,name=:t.name,descs=:t.descs,stickAt=:t.stickAt,orderNo=:t.orderNo,updateUser=:t.updateUser,updateAt=now() WHERE id=:t.id")
    void update(@SQLParam("t") Columns columns);
    
    @SQL("UPDATE Columns SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE Columns SET stickAT=now(),updateAT=now() WHERE id=:1")
    void updateByStickTime(int id);
	
	@SQL("UPDATE Columns SET stickAT=null,updateAT=now() WHERE id=:1")
    void updateByStickTimeIsNull(int id);
	
	@SQL("UPDATE Columns SET status=0,updateAT=now() WHERE id=:1")
    void updateByStatusFb(int id);
	
	@SQL("UPDATE Columns SET status=1,updateAT=now() WHERE id=:1")
    void updateByStatusWfb(int id);
}